package com.rural.bus.driver.adapter;

import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.rural.bus.driver.MainActivity;
import com.rural.bus.driver.MyApplication;
import com.rural.bus.driver.R;
import com.rural.bus.driver.adapter.base.MyBaseAdapter;
import com.rural.bus.driver.adapter.base.ViewHolder;
import com.rural.bus.driver.model.Order;
import com.rural.bus.driver.model.Railway;
import com.rural.bus.driver.model.User;
import com.rural.bus.driver.net.OnNetCallback;
import com.rural.bus.driver.utils.DateUtil;
import com.rural.bus.driver.utils.ProgressUtil;

public class AllMyOrderAdapter extends MyBaseAdapter<Order> {

	private List<Order> mOrders;
	private Context mContext;

	public AllMyOrderAdapter(Context context, List<Order> orders) {
		super(context, orders);
		this.mOrders = orders;
		this.mContext = context;
	}

	@Override
	public int getCount() {
		return mOrders.size();
	}

	@Override
	public Object getItem(int arg0) {
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(final int arg0, View convertView, ViewGroup arg2) {
		ViewHolder holder = null;
		if (convertView == null) {

			holder = new ViewHolder();

			convertView = mInflater.inflate(R.layout.item_my_order_list, null);

			holder.tv_take_time = (TextView) convertView.findViewById(R.id.tv_take_time);
			holder.tv_up_address = (TextView) convertView.findViewById(R.id.tv_up_address);
			holder.tv_down_address = (TextView) convertView.findViewById(R.id.tv_down_address);
			holder.tv_status = (TextView) convertView.findViewById(R.id.tv_status);
			holder.iv_call = (ImageView) convertView.findViewById(R.id.iv_call);

			convertView.setTag(holder);

		} else {

			holder = (ViewHolder) convertView.getTag();
		}

		final Order order = mOrders.get(arg0);
		
		holder.tv_take_time.setText(""+ DateUtil.formatDiscriptionTime(order.takeTime));
		holder.tv_up_address.setText(""+ order.startLocation);
		holder.tv_down_address.setText(""+ order.endLocation);
		
		// STATUS0("新订单", 0),STATUS1("已接单", 1), STATUS2("已就绪", 2),
		// STATUS3("已出发", 3),STATUS4("已取消", 4),STATUS5("已结束", 5), STATUS6("完成",
		// 6), STATUS7("异常 ",7);

				switch (order.orderStatus) {
				case 1:
					holder.tv_status.setText("已接单");
					break;
				case 2:
					holder.tv_status.setText("已就绪");
					break;
				case 3:
					holder.tv_status.setText("已出发");
					break;
				case 4:
					holder.tv_status.setText("已取消");
					break;
				case 5:
					holder.tv_status.setText("已结束");
					break;
				case 6:
					holder.tv_status.setText("已完成");
					break;
				default:
					holder.tv_status.setText("新订单");
					break;
				}
		
		
		holder.iv_call.setVisibility(View.INVISIBLE);;

		return convertView;
	}

	public class ViewHolder {
		TextView tv_take_time;
		TextView tv_up_address;
		TextView tv_down_address;
		ImageView iv_call;
		TextView tv_status;
	}

}
